<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lzy
  Date: 2018/7/28
  Time: 10:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>New Customer Info</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
    </script>

    <script type="text/javascript">
        $(function () {
            $(".delete").click(function () {
                var content = $(this).parent().parent().find("td:eq(1)").text();
                var flag = confirm("确定要删除" + content + "的信息么?");
                return flag;
            });
        });
    </script>
</head>
<body>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
<br>
<form action="${contextPath}/query.do" method="post">
    <table>
        <tr>
            <td>Customer Name</td>
            <td><input type="text" name="name"/></td>
        </tr>
        <tr>
            <td>Address</td>
            <td><input type="text" name="address"/></td>
        </tr>
        <tr>
            <td>Phone:</td>
            <td><input type="text" name="phone"/></td>
        </tr>
        <tr>
            <td><input type="submit" value="Query"/></td>
            <td><a href="${contextPath}/customer2/newcustomer.jsp">Create New Customer</a></td>
        </tr>
    </table>
</form>
<br>
<hr>
<br>

<table border="1" cellpadding="10" cellspacing="1">
    <tr>
        <th>ID</th>
        <th>CustomerName</th>
        <th>Address</th>
        <th>Phone</th>
        <th>UPDATE\DELETE</th>
    </tr>
    <c:if test="${!empty requestScope.customers}">
        <c:forEach items="${requestScope.customers}" var="customer">
            <tr>
                <td>${customer.id}
                </td>
                <td>${customer.name}
                </td>
                <td>${customer.address}
                </td>
                <td>${customer.phone}
                </td>
                <td>
                    <c:url value="${contextPath}/editCustomer.do" var="editUrl">
                        <c:param name="id" value="${customer.id}"/>
                    </c:url>
                    <c:url value="${contextPath}/deleteCustomer.do" var="delUrl">
                        <c:param name="id" value="${customer.id}"/>
                    </c:url>
                    <a href="${editUrl}">UPDATE</a>
                    <a href="${delUrl}" class="delete">DELETE</a>
                </td>
            </tr>
        </c:forEach>
    </c:if>
</table>

</body>
</html>
